package com.ky;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.TimeZone;


/**
 * 民宿管理平台启动类
 *
 * @author kuangyu
 * @date 2025-03-11
 */
@SpringBootApplication
@EnableDiscoveryClient
@Configuration
@ComponentScan(basePackages = { "com.ky.homestay"})
@EnableFeignClients(value = { "com.ky.homestay"})
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
public class HomestayApplication {
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(HomestayApplication.class, args);
        Environment env = application.getEnvironment();
        TimeZone.setDefault(TimeZone.getTimeZone(env.containsProperty("framework.time-zone")?env.getProperty("framework.time-zone"):"Asia/Shanghai"));
        if("dev".equals(env.getProperty("spring.profiles.active"))){
            String path = env.containsProperty("server.servlet.context-path")?env.getProperty("server.servlet.context-path"):"/";
            System.out.println(String.format("\n----------------------------------------------------------\n\t" +
                            "应用 '%s' 启动成功! 访问链接:\n\t" +
                            "访问地址: \thttp://%s:%s%s\n\t"+
                            "接口API文档: \thttp://%s:%s%sdoc.html\n\t"+
                            "数据库监控: \thttp://127.0.0.1:%s%sdruid/index.html\n" +
                            "----------------------------------------------------------",
                    env.getProperty("spring.application.name"),
                    InetAddress.getLocalHost().getHostAddress(),
                    env.getProperty("server.port"),
                    path,
                    InetAddress.getLocalHost().getHostAddress(),
                    env.getProperty("server.port"),
                    path,
                    env.getProperty("server.port"),
                    path));
        }
    }
}
